package com.cdu.guoxinan.www.smartcom.controller;

import com.cdu.guoxinan.www.smartcom.domian.dto.VehicleQueryDTO;
import com.cdu.guoxinan.www.smartcom.domian.pojo.Vehicle;
import com.cdu.guoxinan.www.smartcom.domian.vo.VehicleVO;
import com.cdu.guoxinan.www.smartcom.service.VehicleService;
import com.cdu.guoxinan.www.smartcom.unit.model.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/vehicle")
@Api(tags = "车辆管理控制器")
public class VehicleController {
    @Resource
    private VehicleService vehicleService;

    @GetMapping("/queryPage")
    @ApiOperation("分页查询车辆信息")
    public R queryPage(VehicleQueryDTO vehicleQueryDTO){
        System.out.println("hasParkingSpot: " + vehicleQueryDTO.getHasParkingSpot());
        PageInfo<VehicleVO> pageInfo = vehicleService.queryPage(vehicleQueryDTO);
        return R.ok(pageInfo);
    }

    @PostMapping("/add")
    @ApiOperation("添加车辆信息")
    public R add(Vehicle vehicle){
        return vehicleService.add(vehicle)?R.ok("添加成功"):R.error("添加失败");
    }
    @PostMapping("/update")
    @ApiOperation("修改车辆信息")
    public R update(Vehicle vehicle){
        return vehicleService.update(vehicle)?R.ok("修改成功"):R.error("修改失败");
    }
    @PostMapping("/delete")
    @ApiOperation("删除车辆信息")
    public R delete(Integer id){
        return vehicleService.delete(id)?R.ok("删除成功"):R.error("删除失败");
    }

    @PostMapping("/parkingSpot")
    @ApiOperation("分配车位")
    public R parkingSpot(Vehicle vehicle){
        return vehicleService.parkingSpot(vehicle)?R.ok("分配成功"):R.error("分配失败");
    }
}
